package top.jsjkxyjs.blackbox.service.impl;

import com.baomidou.mybatisplus.annotation.TableName;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.jsjkxyjs.blackbox.entity.Car;
import top.jsjkxyjs.blackbox.entity.User;
import top.jsjkxyjs.blackbox.mapper.UserMapper;
import top.jsjkxyjs.blackbox.service.UserService;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@TableName("user")
@Service
public class UserServiceImpl implements UserService {
	@Autowired
	UserMapper userMapper;

	@Override
	public User checkLogin(User user) {
		User userList = userMapper.checkUser(user);
		return userList;
	}


	@Override
	public List<User> getAllUsers() {
		Map<String, Object> map = new HashMap<>();
		map.put("Role", 1);
		return userMapper.selectByMap(map);
	}

	@Override
	public boolean bindCartoUser(User user, Car car) {
		int number = userMapper.bindCartoUser(user.getId(), car);
		return number > 0;
	}

	@Override
	public User register(User user) {
		userMapper.insert(user);
		return user;
	}

	@Override
	public boolean foundUser(String phone) {
		int number = userMapper.findByPhone(phone);
		return number > 0;
	}

	@Override
	public boolean changeUserInfo(User user) {
		user.setRole(1);
		int number = userMapper.updateById(user);
		return number > 0;
	}

	@Override
	public User getUserByUserId(int userId) {
		return userMapper.selectById(userId);
	}
}
